<?php


namespace app\common\controller;
use OSS\OssClient;
use OSS\Core\OssException;

class OssStorage
{
  public static function fileHandle($file){
      $src = $file->getInfo()['tmp_name'];
      $ext = substr($file->getInfo()['name'],strrpos($file->getInfo()['name'],'.')+1);
      $dst = md5(time()).'.'.$ext;
      return $data = [
          'src'       =>         $src,
          'ext'       =>         $ext,
          'dst'       =>         $dst
      ];
  }
    public static function upload($dst,$src){
        $accessKeyId = env('SMS_ACCESSKEY');
        $accessKeySecret = env('SMS_ACCESSKEYSECRET');
        // Endpoint以杭州为例，其它Region请按实际情况填写。
        $endpoint = env('OSS_UPLOAD_URL');
        $bucket = '19jwshow';

        @error_reporting (E_ALL & ~E_NOTICE & ~E_WARNING);

        //获取对象
        $auth = new OssClient($accessKeyId,$accessKeySecret,$endpoint);
        $object ='recruit/upload/' . $dst;
        try {
            //上传图片
            $result  = $auth->uploadFile($bucket,$object,$src);
            return $result['info']['url'];
        } catch (OssException $e) {
            return $e->getMessage();
        }
    }
}